import request from '@/utils/request'

export function upload(url, data) {
  return new Promise((resolve) => {
    let progress = 0
    request({
      url,
      method: 'post',
      headers: {
        'Content-Type': 'multiple/form-data'
      },
      onUploadProgress: (progressEvent) => {
        if (progressEvent.lengthComputable) {
          progress = Math.round(
            (progressEvent.loaded / progressEvent.total) * 100
          )
        }
      },
      data
    }).then(res => {
      resolve({
        res,
        progress
      })
    })
  })
}
